﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.factory;
using Imaginecup.sprite.changeSourceSize;
using Imaginecup.sprite.rotate;
using Imaginecup.sprite.animation;

namespace Imaginecup.sprite.factory
{
    public enum SPRITE_TYPE_ID { CHANGESOURCE_SPRITE, NORMAL_SPRITE, COMPOSITE_SPRITE, RELATIVE_SPRITE, ROTATE_SPRITE, ANIMATION_SPRITE, ANIMATION_SPRITE_ADDITIVE }

    public struct FactorySpriteInfo
    {
        public FactorySpriteInfo(SPRITE_TYPE_ID id , String textureName , Object extra)
        {
            typeID = id;
            TextureName = textureName;
            extraInfo = extra;
        }

        public SPRITE_TYPE_ID typeID;
        public String TextureName;
        public Object extraInfo;
    }

    public class SpriteFactory:IFactory
    {
        public object GetObject(object info)
        {
            FactorySpriteInfo factoryInfo = (FactorySpriteInfo)info;

            return CreateSprite( factoryInfo.typeID , factoryInfo.TextureName , factoryInfo.extraInfo);
        }

         private ISprite CreateSprite( SPRITE_TYPE_ID typeID , String TextureName ,  Object extraInfo)
        {
        
            //case문에 상황에 따라 사용되는 것들.(가독성을 위해 뺏음)
            ChangeSourceSizeSprite changeSprite;
            RelativeSprite relativeSprite;
            NormalSprite normalSprite;

            RotateSprite rotateSprite;
            CompositeSprite compositeSprite;
            AnimationSprite animationSprite;



            switch( typeID )
            {
                case SPRITE_TYPE_ID.NORMAL_SPRITE:
                    normalSprite = new NormalSprite();
                    normalSprite.SetTextureName(TextureName);
                    
                    return normalSprite;

                case SPRITE_TYPE_ID.ANIMATION_SPRITE_ADDITIVE:
                    animationSprite = new AnimationSprite((IAnimationIndexProvider)extraInfo , true);
                    animationSprite.SetTextureName(TextureName);

                    return animationSprite;

                case SPRITE_TYPE_ID.ANIMATION_SPRITE:
                    animationSprite = new AnimationSprite((IAnimationIndexProvider)extraInfo);
                    animationSprite.SetTextureName(TextureName);

                    return animationSprite;
                case SPRITE_TYPE_ID.CHANGESOURCE_SPRITE:
                    changeSprite = new ChangeSourceSizeSprite();
                    changeSprite.SetSourceInfoClass((ISourceInfoClass)extraInfo );
                    changeSprite.SetTextureName(TextureName);

                    return changeSprite;

                case SPRITE_TYPE_ID.COMPOSITE_SPRITE:
                    List<ISprite> spriteList = (List<ISprite>)extraInfo;
                    compositeSprite = new CompositeSprite();

                    foreach(ISprite sprite in spriteList)
                    {
                        compositeSprite.AddSprite(sprite);
                    }
                    
                    return compositeSprite;

                case SPRITE_TYPE_ID.RELATIVE_SPRITE:
                    relativeSprite = new RelativeSprite();
                    relativeSprite.SetRelativeInfo((IRelativeSourceInfoClass)extraInfo);
                    relativeSprite.SetTextureName(TextureName);
                    return relativeSprite;

                case SPRITE_TYPE_ID.ROTATE_SPRITE:
                    rotateSprite = new RotateSprite();
                    rotateSprite.SetRotateInfo((IRotateInfo)extraInfo);
                    return rotateSprite;
            
            }
            return null;
        }    
    }
}
